package com.ccom.core.common.exception;

import com.ccom.core.common.api.IResultCode;
import lombok.Data;

/**
 * @author zjj
 * @date 2021/10/29 15:53
 * @description 自定义系统全局异常 CcomBootException
 */
@Data
public class CcomBootException extends RuntimeException {

    private static final String ERROR = "服务异常";

    private static final long serialVersionUID = 1L;

    /**
     * 错误码
     */
    private Integer code;

    /**
     * 错误消息
     */
    private String defaultMessage;

    public CcomBootException(Integer code, String defaultMessage) {
        this.code = code;
        this.defaultMessage = defaultMessage;
    }

    public CcomBootException(Integer code) {
        this.code = code;
        this.defaultMessage = ERROR;
    }

    public CcomBootException(String defaultMessage) {
        this.code = 500;
        this.defaultMessage = defaultMessage;
    }

    public CcomBootException(IResultCode resultCode) {
        this.code = resultCode.getCode();
        this.defaultMessage = resultCode.getMessage();
    }
}
